home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / AimChangePassword.js < prev    next >
Encoding:
Text File  |  2001-10-21  |  4.1 KB  |  140 lines

  1. var aimAdminInfoCallback = new Object();
  2. var adminManager;
  3. var newPassword2;
  4. var newPassword1;
  5. var oldPassword;
  6.  
  7. aimAdminInfoCallback.OnChangeInfoComplete = function(aimAdminInfoType)
  8. {
  9.     aimErrorBox(aimString("msg.changePasswordSucess"));
  10.     window.close();
  11. }
  12.  
  13. aimAdminInfoCallback.OnChangeInfoError = function(aimAdminInfoType, errMsg)
  14. {
  15.     aimErrorBox(errMsg);
  16.     window.close();
  17. }
  18.  
  19. aimAdminInfoCallback.OnRequestInfoComplete = function(aimAdminInfoType, info)
  20. {
  21.     // Nothing fow now.
  22. }
  23.  
  24. aimAdminInfoCallback.OnRequestInfoError = function(aimAdminInfoType, errMsg)
  25. {
  26.     // Nothing fow now.
  27. }
  28.  
  29. myAdminExecutionCallback = new Object();
  30. myAdminExecutionCallback.ExecuteIfReady = function()
  31. {
  32.   try {
  33.     adminManager.ChangePassword(aimAdminInfoCallback, newPassword2, oldPassword);
  34.   }
  35.   catch(ex) {
  36.     dump("Failed to call ChangePassword. EX= " + ex + "\n");
  37.   }
  38.  
  39. }
  40.  
  41. function AimChangePasswordWndOnLoad() {
  42.   document.getElementById("mydeck").setAttribute("selectedIndex",0);
  43.   doSetOKCancel(onOK, 0);
  44.   document.getElementById("fldoldPassword").focus();
  45. }
  46.  
  47. /* 
  48.  * Name: onOK (ChangePassword SC-01-01)
  49.  *
  50.  * Description:
  51.  *
  52.  * This function is called by the dialog overlay if the user hits the OK
  53.  * button in the change password dialog. The function grabs the old, new
  54.  * and confirm password from the dialog. It confirms that the lengths of
  55.  * these password are valid, and displays error messages if not. These
  56.  * passwords are stored in global variables by this function. Then an 
  57.  * instance of nsIAimAdminManager is obtained, and its ExecuteIfReady
  58.  * method is called. ExecuteIfReady will asynchronously invoke the 
  59.  * myAdminExecutionCallback object, which is passed to 
  60.  * nsIAimManager::ExecuteIfReady via its ExecuteIfReady function, and 
  61.  * it is from there that we actually call into AIM Glue to have the
  62.  * password changed. 
  63.  *
  64.  * Return Value: none
  65.  *
  66.  * Original Code: Suresh Kasinathan
  67.  *
  68. */
  69.  
  70. function onOK() {
  71.  
  72.   /* get the values the user entered, and store in global variables
  73.      so the ExecuteIfReady callback will be able to access them */
  74.  
  75.   newPassword1 = document.getElementById("fldNewPassword1").value;
  76.   newPassword2 = document.getElementById("fldNewPassword2").value;
  77.   oldPassword = document.getElementById("fldoldPassword").value;
  78.  
  79.   /* validate the passwords and display errors if not of the correct
  80.      lengths */
  81.  
  82.   if((oldPassword.length < 4) || (oldPassword.length > 16)) {
  83.       aimErrorBox(aimString("msg.BadOldPasswordlength"));
  84.     return;
  85.   }
  86.  
  87.   if(newPassword1 != newPassword2) {
  88.     aimErrorBox(aimString("msg.BadNewPassword"));
  89.     return;
  90.   }
  91.  
  92.   if((newPassword1.length < 4) || (newPassword1.length > 16) || (newPassword2.length < 4) || (newPassword2.length > 16)) {
  93.     aimErrorBox(aimString("msg.BadNewPasswordlength"));
  94.     return;
  95.   }
  96.  
  97.   /* if the passwords are the same, say the password change was successful.
  98.      XXX what if the user thought they typed in a different password? The
  99.      next time they login, it will fail them. We should display a message
  100.      here that tells them the password was not changed because they entered
  101.      the same value as the old password */
  102.  
  103.   if(newPassword1 == oldPassword) {
  104.     aimErrorBox(aimString("msg.changePasswordSucess"));
  105.     window.close();
  106.     return;
  107.   }
  108.  
  109.   /* XXX I don't know what this line of code does */
  110.  
  111.   document.getElementById("mydeck").setAttribute("selectedIndex",1);
  112.  
  113.   /* get an interface to nsIAimAdminManager */
  114.  
  115.   adminManager = aimAdminManager();
  116.   if (!adminManager) {
  117.     dump("Trying to create nsIAimAdminManager on my own..\n");
  118.     adminManager = Components.classes['@netscape.com/aim/IMManager;1'].getService(Components.interfaces.nsIIMManager).QueryInterface(Components.interfaces.nsIAimAdminManager);
  119.     if(!adminManager) {
  120.       dump("Unable to create nsIAimAdminManager..\n");
  121.       return;
  122.     }
  123.   }
  124.  
  125.   /* call ExecuteIfReady and pass our callback object so that IM Glue can
  126.      call us when it is ready for us to actually change the password */
  127.     
  128.   try {
  129.     adminManager.ExecuteIfReady(myAdminExecutionCallback);
  130.   }
  131.   catch(e) {
  132.     dump("Unable to call ExecuteIfReady. ex = " + ex + "\n");
  133.   }
  134.  
  135. }
  136.  
  137.  
  138.  
  139.  
  140.